import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
from PIL import Image as PILImage
import io
data="""YSBS20255b-2009-1  0.155   0.1536  0.162725172
YSBS20255b-2009-2  0.43    0.4327  0.458406131
YSBS20255b-2009-3  0.67    0.6538  0.692641388
YSBS20255b-2009-5  0.0028  0.0027  0.002860403
YSBS20255b-2009-6  0.142   0.1394  0.147681568
YSBS20255b-2009-7  0.664   0.6183  0.65503238
GSB03-2453-2008-2  0.256   0.2409  0.255211548
GSB03-2453-2008-4  0.085   0.0849  0.089943796
YSBS11279-2000  0.803   0.7395  0.783432711
9902-GBW(E)010137   1.21    1.1099  1.175837682
Q235-YSBS11173a-2007    0.188   0.1942  0.205737164
16MnV5-YSBC35201-97-211 0.171   0.1646  0.174378667
Q345b-YSBS11264a-2011   0.158   0.1593  0.168763801
YSBS11078d-2012    0.0018  0.0016  0.001695054
BS1020 0.21    0.2138  0.226501573
GCr15-YSBS11273b-2007   0.999   0.962   1.01915114"""
data=data.split("\n")
for i in range(len(data)):
    data[i]=data[i].split(" ")
    data[i] = list(filter(lambda x: x!="", data[i]))
std=[]
measure=[]
yfited=[]
for i in range(len(data)):
    std.append(float(data[i][1]))
    measure.append(float(data[i][2]))
    yfited.append(float(data[i][3]))
print(measure,std,yfited)
matplotlib.use('qtAGG')
fig, ax = plt.subplots()  # Create a figure containing a single axes.
ax.scatter(measure, std,c="red", picker=5)  # Plot some data on the axes.
ax.plot(measure,yfited)
# fig = plt.figure()
# ax = fig.add_subplot(111)
# ax.set_title('click on points')
# line, = ax.plot(np.random.rand(100), 'o', picker=5)  # 5 points tolerance
selected=[]
def onpick(event):
    global selected
    thisline = event.artist
    print(dir(thisline),thisline)
    print(thisline[event.ind])
    # xdata = thisline.get_xdata()
    # ydata = thisline.get_ydata()
    thisline.set_alpha(0.5)
    # thisline.update()
    # ind = event.ind
    # points = tuple(zip(xdata[ind], ydata[ind]))
    # for point in points:
    #     if point in selected:
    #         pass
    #     else:
    #         selected.append(point)
    # print(selected)
    event.canvas.draw()
fig.canvas.mpl_connect('pick_event', onpick)
plt.show()